import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import en from 'element-plus/es/locale/lang/en'

import App from './App.vue'
import router from './router'
import pinia from './store'
import { useUserStore } from './store/user'
import i18n from './locales'

// 导入全局样式
import './styles/index.scss'

const app = createApp(App)

// 根据当前语言设置Element Plus的语言
const currentLanguage = localStorage.getItem('language') || 'zh'
app.use(ElementPlus, {
  locale: currentLanguage === 'zh' ? zhCn : en
})

// 使用插件
app.use(router)
app.use(pinia)
app.use(i18n)

// 初始化用户状态
const userStore = useUserStore()
userStore.initializeFromLocalStorage()

// 挂载应用
app.mount('#app')